public class Test1 {
    //leetcode 破冰游戏
    //https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/description/?envType=problem-list-v2&envId=recursion

    /**
     * 递归
     * @param num
     * @param target
     * @return
     */
    public int iceBreakingGame(int num, int target) {
        return f(num,target);
    }

    private int f(int num, int target) {
        if (num == 1) return 0;
        int x = f(num-1,target);
        return (x + target) % num;
    }

    /**
     * 非递归
     * @param num
     * @param target
     * @return
     */
    public int iceBreakingGame1(int num, int target) {
        int f = 0;
        for (int i = 2; i != num + 1; ++i) {
            f = (target + f) % i;
        }
        return f;
    }

}
